<template>
  <el-dialog
    title="发送消息"
    :visible.sync="visible"
    :close-on-click-modal="false"
    top="8vh"
    width="30%"
  >
    <el-form :model="form" ref="form">
      <el-form-item prop="content">
        <el-input v-model="form.content"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="">
      <el-button class="px-12" type="primary" @click="onSubmit"
        >确 定</el-button
      >
      <el-button class="px-12" plain @click="visible = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      form: {
        content: "",
        to: "",
      },
    };
  },
  methods: {
    open(row) {
      this.form.to = row.uid;
      this.form.content = "";
      this.visible = true;
    },
    onSubmit() {
      if (this.form.content === "") return;
      this.axios.post(`/user/sendMsg`, this.form).then((res) => {
        if (res.retCode != 0) {
          return this.$message.error(res.retMsg);
        }
        this.$emit("added");
        this.$message.success("操作成功!");
        this.visible = false;
      });
    },
  },
};
</script>